<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

  defined('_JEXEC') or die('Retricted Access');

    JHTML::_('behavior.tooltip');
    $editor = &JFactory::getEditor();
    $user = &JFactory::getUser();
    if ($user->get('lastvisitDate') == "0000-00-00 00:00:00") {
		$lvisit = JText::_( 'Never' );
	} else {
		$lvisit	= generateDate($user->get('lastvisitDate'));
	}
	$user_type = JRequest::getVar('user_type');
	$owner_resume = 0;
	
	// Google map data
	global $jbconfig;	
	$mapLocation = $jbconfig['general']->get('map_ja_resumes', "address");
?>
<script type="text/javascript" language="javascript">
/* <![CDATA[ */

    function submitbutton_resume(pressbutton,form_id){
        var form_resume = $(form_id);
        form_resume.task.value = pressbutton;
        form_resume.submit();
    }
    
    function show_div_content(id,item_id){
    	
        var ele2 = document.getElementById('feedback_' + item_id);
        var ele3 = document.getElementById('add_note_' + item_id);
        if(id == 'feedback_'+item_id){
            if(ele2.style != null){
                ele2.style.display = ele2.style.display == 'none' ? 'block' : 'none';
            }
            if (ele3) ele3.style.display = 'none';
        } else if (id == 'add_note_'+item_id){
        	if(ele3.style != null){
                ele3.style.display = ele3.style.display == 'none' ? 'block' : 'none';
            if (ele2) ele2.style.display = 'none';    
            }
        }
    }
    function check_submit_jobseeker(form_id)
	{
		form = document.getElementById(form_id);
		confirm_message = '<?php echo JText::_('Email content is empty. Do you want to send this mail?'); ?>';
		$message = form.message.value;
		subject = form.subject.value;
		label_error = document.getElementById('error_message_jobseeker');
		if (subject=='')
		{
			alert('<?php echo JText::_('Subject must not be empty!'); ?>');
			label_error.innerHTML = '<?php echo JText::_('Subject must not be empty!');?>';
			label_error.style.display = 'block';
			return;
		}
		if (($message.trim()==''))
		{
			s = confirm(confirm_message);
			if (s)	
				form.submit();
		}
		else	
		{
		
			form.submit();
		}
		
	}

/* ]]> */    
</script>
<div id="jobboard-content">
<?php 
	if (count($this->items)==1) 
		if ($user->id==$this->items[0]->user_id) { $owner_resume = 1;?>
<div class="moduletable job-box">	

	<form name="userdetailForm" action="<?php echo JURI::root();?>index.php" method="post">
		<?php if (getCurrentUserType($user->id)=='Guest') { ?>
		<table class="tabledata userdetails">
			<tr>
				<td>
				
					<?php echo JText::_('You don\'t have update your information detail!'); ?>
					<a class="button" href="<?php echo JRoute::_( 'index.php?option=com_jajobboard&view=usergroup'); ?>"><?php echo JText::_('Update now'); ?></a>
				
				</td>
			</tr>
		</table>
		<?php } ?>
      	<h3>
	          <?php echo JText::_( 'Information details' ); ?>
	    </h3>
	    <table class="tabledata userdetails">												
			<tr>
				<td class="key">
					<?php echo JText::_('Name'); ?>
				</td>
				<td>
					<?php echo $user->get('name'); ?>
				</td>
			</tr>
			<tr>
				<td class="key">
					<?php echo JText::_('Username'); ?>
				</td>
				<td>
					<?php echo $user->get('username'); ?>
				</td>
			</tr>
			<tr>
				<td class="key">
					<?php echo JText::_('Email'); ?>
				</td>
				<td>
					<?php echo $user->get('email'); ?>
				</td>
			</tr>
			
			<?php  if( $user->get('id') ) { ?>
			<tr>
				<td class="key">
					<?php echo JText::_('Register Date'); ?>:
				</td>
				<td>
					<?php echo generateDate($user->get('registerDate'));?>
				</td>
			</tr>
			<tr>
				<td class="key">
					<?php echo JText::_('Last Visit Date'); ?>:
				</td>
				<td>
					<?php echo $lvisit; ?>
				</td>
			</tr>
			<?php } ?>
			
		</table>
		<table class="tabledata userdetails">
			<tr>
				<td align="right" style="text-align: right !important">
					<?php if (JRequest::getVar('view')!='jausergroup'){?>
						<img title="<?php echo JText::_('Edit resume'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/icon_edit.png' ?>" alt="<?php echo JText::_('Edit resume'); ?>" />
	                    &nbsp;
	                    <a href="<?php echo JRoute::_( 'index.php?option=com_user&view=user&layout=form&Itemid='.$this->Itemid); ?>" title="<?php echo JText::_('Click here to edit your detail')?>">
	                    	<span style="vertical-align: top !important;"><?php echo JText::_('Edit My Detail'); ?></span>
	                    </a>				
					<?php }?>
				</td>
			</tr>
		</table>
		
		
		<input type="hidden" name="cid" value="<?php echo $user->id; ?>" />
		<input type="hidden" name="option" value="<?php echo $option; ?>" />
		<input type="hidden" name="view" value="usergroup" />
		<input type="hidden" name="task" value="" />
		<?php echo JHTML::_( 'form.token' ); ?>	
		
		        
	</form>
</div>

<?php } ?>

<?php 
if (count($this->items)>0)
{
	$db = JFactory::getDBO();
	foreach  ($this->items as $item) {
	JFilterOutput::objectHTMLSafe( $item );
	$this->item = $item;
	if (isset($this->notes[$item->id]))
		$this->note = $this->notes[$item->id];
	else 
	{
		require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables'.DS.'ja_notes.php');
		$this->note = new JobBoardTableJA_Notes($db);
	}
?>
<div <?php echo !$owner_resume?'id="ja-splitcontent"':'';?>>
<h2><?php echo $this->item->title; ?></h2>
<form id="adminForm_<?php echo $this->item->id; ?>" name="adminForm_<?php echo $this->item->id; ?>" action="<?php echo JURI::root();?>index.php" method="post">
	<?php if(getCurrentUserType() == JBEMPLOYER_USER) { ?>
	<div style="float: right;">
		<!-- AddThis Button BEGIN -->
		<a href="http://www.addthis.com/bookmark.php?v=250&amp;pub=xa-4a764a015f702d7f" onmouseover="return addthis_open(this, '', '[URL]', '[TITLE]')" onmouseout="addthis_close()" onclick="return addthis_sendto()">
			<img src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Bookmark and Share" style="border: 0pt none ;" width="125" height="16">
		</a>
		<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js?pub=xa-4a764a015f702d7f"></script>

		<!-- AddThis Button END -->
	</div>
	<?php } ?>
        <div class="moduletable resume-box">
			<table class="tabledata resumedetails">
			  	
		        <?php
		        $k=0;
		        for($i = 0, $n = count($this->fieldlist); $i < $n; $i++ ){		        	
		            $field = $this->fieldlist[$i];
		           
		            if($field->display=='admin_only' && $user->aid<2) continue;
		            
		            if($field->display=='hide_all' || $field->display=='hide_on_view') continue;
		            
		            $input = rendfield($this->item, $field, false, true, true);
		            $firstIndex = findFirstField($this->item,$this->fieldlist);
		   			$lastIndex = findLastField($this->item,$this->fieldlist); 
		   					   					   			
		   			if($field->field_type=='SEPERATOR' ){?>
		   			
		    </table>
			</div>
		
		  	<div class="moduletable resume-box"> 
		  		<?php if($input!=''){?>
				<h3><?php echo $input;?></h3>
				<?php }?>
				<table class="tabledata resumedetails">
			    <?php }else{
                        	if ( $i == $firstIndex )
					      		$classname = 'first sectiontableentry'.($k+1);
					      	elseif ($i==$lastIndex)
					      	{
					      		if (getCurrentUserType() != JBJOB_SEEKER_USER || $this->item->user_id != $user->id)	
					      			$classname = 'last sectiontableentry'.($k+1);
					      		else 
					      			$classname = 'sectiontableentry'.($k+1);
					      	}
					      	else 
					      		$classname = 'sectiontableentry'.($k+1);
                        ?>
	               		<tr class="<?php echo $classname; ?>">
	                        <td width="20%" style="text-align:left;" valign="top" class="jajb-title">
	                        <?php echo JText::_($field->label); ?>:
	                        </td>
	                        <td width="80%">
	                           <?php echo $input;?>
	                           <?php 
					           	// Check to show Google Map
					           	if( $field->field_name == $mapLocation && $input != "") {?>
					           	{jamap to_location='<?php echo $input;?>'}
					           	<?php }?>
	                        </td>
	                    </tr>      
		                
	                	<?php $k = 1 - $k;
	               }
                }
                ?>
				
                <!-- 
                <?php if(getCurrentUserType() == JBJOB_SEEKER_USER && $this->item->user_id == $user->id){?>
                <?php $classname = 'sectiontableentry'.($k+1); $k = 1 - $k;?>
                <tr class="<?php echo $classname?>">                	
                	<td width="20%" class="jajb-title">
                    	<?php echo JText::_('Published'); ?>:
                    </td>
                    <td width="80%">
                      <?php echo $this->item->published?JText::_('Yes'):JText::_('No'); ?>
                    </td>
                </tr>
                <?php $classname = 'sectiontableentry'.($k+1); $k = 1 - $k;?>
                <tr class="<?php echo $classname?> last">
                	<td width="20%" class="jajb-title">
                    	<?php echo JText::_('Status'); ?>:
                    </td>
                    <td width="80%">
                      <?php echo $this->item->approved?JText::_('Approved'):JText::_('Non-Approved'); ?>
                    </td>
                </tr>
                <?php }?>
                
                -->
		    </table>
		    
        
		</div>
		<br />
		

    <div class="clr"></div>
    
	<input type="hidden" name="cid[]" value="<?php echo $this->item->id; ?>" />
	<input type="hidden" name="alias" value="<?php $temp = JFactory::getUser($this->item->user_id);echo JFilterOutput::stringURLSafe($temp->name); ?>" />
	<input type="hidden" name="option" value="<?php echo JBCOMNAME; ?>" />
	<input type="hidden" name="view" value="jaresumes" />
	<input type="hidden" name="layout" value="jalist" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="1" />
    <input type="hidden" name="Itemid" value="<?php echo $this->Itemid; ?>" />
	<?php echo JHTML::_( 'form.token' ); ?>	
 </form>
 
    	<table class="tabledata resumedetails">
        <tr>
            <?php if(JRequest::getVar('step') == 'verify') {?>
            <td>
                <a class="button" href="<?php echo JRoute::_( 'index.php?option='. JBCOMNAME .'&amp;view=jaresumes&task=save&amp;step=done&amp;cid[]='.$this->item->id.'&amp;Itemid='. $this->Itemid ); ?>">
                <?php echo JText::_('Done'); ?></a>&nbsp;
                <a class="button" href="<?php echo JRoute::_( 'index.php?option='. JBCOMNAME .'&amp;view=jaresumes&amp;layout=jaform&amp;cid[]='.$this->item->id.'&Itemid='. $this->Itemid ); ?>"><?php echo JText::_('Modify'); ?></a>
            </td>
            <?php } else {?>
            <td style="text-align:right !important;border-bottom: 1px solid #E5E5E5 !important;">
                <?php  
                if (isset($this->item)){
	                if(getCurrentUserType() == JBJOB_SEEKER_USER && $this->item->user_id == $user->id){
	                    $alias = JFilterOutput::stringURLSafe($user->name);
	                    ?>
	                    <img title="<?php echo JText::_('Edit resume'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/icon_edit.png' ?>" alt="<?php echo JText::_('Edit resume'); ?>" />
	                    &nbsp;
	                    <a href="<?php echo JRoute::_('index.php?option='.JBCOMNAME.'&amp;view=jaresumes&layout=jaform&amp;cid[]='.$this->item->id. '&amp;alias='.$alias .'&amp;Itemid='. $this->Itemid) ?>" >
	                    	<span style="vertical-align: top !important;"><?php echo JText::_('Edit resume'); ?></span>
	                    </a> 
	                    &nbsp;
	                    <img title="<?php echo JText::_('Delete resume'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/icon_delete.gif' ?>" alt="<?php echo JText::_('Delete resume'); ?>" />
	                    &nbsp;
	                    <a onclick="return confirm('<?php echo JText::_('Do you want to delete your resume')."?"; ?>');" href="javascript:submitbutton_resume('remove','adminForm_<?php echo $this->item->id; ?>')" >
	                    	
	                    	<span style="vertical-align: top !important;"><?php echo JText::_('Delete resume'); ?></span>
	                    </a> 
	                    &nbsp;
                	<?php } else if(getCurrentUserType() == JBEMPLOYER_USER){ 
                			if (!check_in_shortlist($user->id,$this->item->id,'ja_resumes')){?>
                	
								<img title="<?php echo JText::_('Favorite'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/Favorites-16x16.png' ?>" alt="<?php echo JText::_('Favorite'); ?>" />
								&nbsp;                	
			                	<a href="javascript:submitbutton_resume('starred','adminForm_<?php echo $this->item->id; ?>')"  >
			        				<span style="vertical-align: top !important;"><?php echo JText::_('Favorite'); ?></span>
			                	</a>&nbsp;
                			<?php } ?>
                			
		                	<img title="<?php echo JText::_('Send mail to job-seeker'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/Mail-16x16.png' ?>" alt="<?php echo JText::_('Send mail to job-seeker'); ?>" />
		                	&nbsp;
		                    <a href="javascript:show_div_content('feedback_<?php echo $this->item->id; ?>','<?php echo $item->id; ?>');" >
		                    	<span style="vertical-align: top !important;"><?php echo JText::_('Send email to job-seeker'); ?></span>
		                    </a>
		                    
			                <?php if (!$this->note->id) {?>
			                	&nbsp;&nbsp;&nbsp;
				                <span id="div_addnote_button_<?php echo $item->id; ?>">
					        		<img title="<?php echo JText::_('Add note'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/Add-16x16.png' ?>" alt="<?php echo JText::_('Add note'); ?>" /> 					                 
					                &nbsp;
									<a href="javascript:show_div_content('add_note_<?php echo $item->id; ?>','<?php echo $item->id; ?>')" >
					                	<span style="vertical-align: top !important;"><?php echo JText::_('Add note'); ?></span>
					                </a>
					                &nbsp; &nbsp;
				                </span>
			       			<?php } ?>
                    
		                <?php } else if(!$user->id) {?>
		                	<img title="<?php echo JText::_('Send mail to job-seeker'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/Mail-16x16.png' ?>" alt="<?php echo JText::_('Send mail to job-seeker'); ?>" />
		                	&nbsp;
		                    <a onclick="alert('<?php echo JText::_('Please login or register before doing this action')?>')" href="<?php echo JRoute::_( 'index.php?option=com_user&amp;view=login&amp;Itemid='. $this->Itemid ); ?>" >
		                    	<span style="vertical-align: top !important;"><?php echo JText::_('Send email to this user'); ?></span>
		                    </a>
		                <?php }  ?>
		                
		                <?php if (isset($this->fromsearch)) if($this->fromsearch == 1) {?>
		                	<img title="<?php echo JText::_('Back'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/Undo-16x16.png' ?>" alt="<?php echo JText::_('Back'); ?>" />
							&nbsp;
							<a href="<?php echo JRoute::_( 'index.php?option='. JBCOMNAME .'&amp;view=jasearch&amp;table_name=ja_resumes&amp;task=search&amp;Itemid='. $this->Itemid ); ?>" title="Back">
								<span style="vertical-align: top !important;"><?php echo JText::_('Back'); ?></span>
							</a> 
		                <?php } else { ?>
		                	<img title="<?php echo JText::_('Back'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/Undo-16x16.png' ?>" alt="<?php echo JText::_('Back'); ?>" />
							&nbsp;
							<a href="javascript:window.history.go(-1);" title="Back">
								<span style="vertical-align: top !important;"><?php echo JText::_('Back'); ?></span>
							</a> 
		                <?php } ?>
		            <?php } ?>
            </td>
            <?php } ?>
        </tr>
    </table>
 <br />
 </div>
 

	<!--Send to Job Seeker-->
	<?php if(getCurrentUserType() == JBEMPLOYER_USER):?>
	<br />
		<?php if (!JRequest::getVar('mail_postback_jobseeker')) {?>
		<div id="feedback_<?php echo $this->item->id; ?>" style="display:none; margin-top:20">
		<?php } else { ?>
		<div id="feedback_<?php echo $this->item->id; ?>" style="display:block; margin-top:20">
		<?php } ?>
		     <?php include(dirname(__FILE__).DS.'sendtouser.php');?>  
		</div>
	<?php endif;?>
		
	<?php if(getCurrentUserType() == JBEMPLOYER_USER):?>
		<?php if (!$this->note->id) {?>	
		<div id="add_note_<?php echo $item->id; ?>" class="moduletable" style="display:none">
		<?php } else {?>
		<div id="div_view_note_<?php echo $item->id; ?>" class="moduletable">
		<?php } ?>		
				<?php include(JPATH_COMPONENT.DS.'views'.DS.'jajobs'.DS.'tmpl'.DS.'add_notes.php');?>
		</div>
	<?php endif; ?>
<?php 
	}	
} 
elseif (!JRequest::getVar('cid')&&$user->id)
{
	
	JError::raiseNotice(0, JText::_('Now, you do not have a resume. Please create your resume.'));							    							
    ?>
    <div style="text-align:center">
	    <a href="<?php echo JRoute::_('index.php?option='.JBCOMNAME.'&amp;view=jaresumes&layout=jaform')?>">
	    	<?php echo JText::_('Create new')?>
	    </a>
    </div>
    <?php
			     
			
}
?>
</div>
<?php if (count($this->items)>5) {?>
<div style="text-align:center">
<form name="adminForm" action="index.php" method="POST">
	<?php echo $this->pagination->getPagesLinks(); ?>
	<br/>
	<?php echo $this->pagination->getPagesCounter(); ?>
	<input type="hidden" name="boxcheck" value="0" />
	<input type="hidden" name="cid[]" value="<?php echo implode(',',JRequest::getVar('cid')); ?>" />
 	<input type="hidden" name="option" value="com_jajobboard" />
	<input type="hidden" name="view" value="jaresumes" />
	<input type="hidden" name="layout" value="jaview" />
    <input type="hidden" name="task" value="" />
    <input type="hidden" name="limitstart" value="<?php echo $this->pagination->limitstart; ?>" />
	<input type="hidden" name="limit" value="<?php echo $this->pagination->limit; ?>" />
	<input type="hidden" name="Itemid" value="<?php echo $this->Itemid;?>" />
</form>
</div>
<?php } ?>